
from rest_framework.viewsets import ModelViewSet,ReadOnlyModelViewSet

from meiduo_admin.serializers.oreders import OrderSerializer
from meiduo_admin.utils import PageNum
from orders.models import OrderInfo
from rest_framework.permissions import IsAdminUser

class OrderView(ReadOnlyModelViewSet):
    serializer_class = OrderSerializer
    queryset = OrderInfo.objects.all()
    pagination_class = PageNum
    permission_classes = [IsAdminUser]


    # 重写获取数据的方法
    def get_queryset(self):

        if self.request.query_params.get('keyword') == '':
            return OrderInfo.objects.all()
        elif self.request.query_params.get('keyword') is None:
            return OrderInfo.objects.all()
        else:
            return OrderInfo.objects.filter(order_id__contains=self.request.query_params.get('keyword'))